package com.flx.at.spring.code.aop;

import com.flx.at.spring.code.aop.calculate.Calculate;
import com.flx.at.spring.code.aop.calculate.Calculator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * @Author: Fenglixiong
 * @Date: 2021/7/3 11:52
 * @Description:
 */
@Slf4j
public class MainApp {

    public static void main(String[] args) {

        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(CalculateConfig.class);
        for (String beanName:ctx.getBeanDefinitionNames()){
            System.out.println("IOC beanName : "+beanName);
        }
        Calculate calculate = (Calculate)ctx.getBean("calculate");
        calculate.div(4,2);

    }

    /**
     * AOP中各个切面方法执行顺序
     * Spring5.2.7之后顺序跟以前不一样
     */
    public void invokeAop(){
        around();
        before();
        try{
            try{
                invokeMethod();
                afterReturning();
            }catch (Exception e){
                afterThrowing();
            }
        }finally {
            after();
        }
        around();
    }

    private void after() {

    }

    private void afterThrowing() {

    }

    private void afterReturning() {

    }

    private void before() {

    }

    private void invokeMethod() {

    }

    private void around() {
    }

}
